package net.sxnic.ugr.user.action;

import java.util.HashSet;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import net.sxnic.ugr.UgrActionSupport;
import net.sxnic.ugr.role.Role;
import net.sxnic.ugr.role.util.RoleUtils;
import net.sxnic.ugr.user.User;

@Controller
@RequestMapping(value = "/admin/ugr/")
public class PreCreate extends UgrActionSupport {

	private String rolesHtml;

	private User user;

	@RequestMapping(value = "user_preCreate.jspa", method = { RequestMethod.POST,
			RequestMethod.GET })
	public String execute(ModelMap model) throws Exception {

		checkRoles(Role.SYSTEM_ADMIN);

		user = new User();

		rolesHtml = RoleUtils.createCheckboxHtml(new HashSet<Role>(),
				authorizationManager.getRoles(), "role");

		user.setUserOrder(userManager.findMaxUserOrder() + 1);

		model.addAttribute("rolesHtml", rolesHtml);
		model.addAttribute("user", user);

		return "/admin/ugr/user/create";
	}
}
